<?php
header("content-type:text/html;charset=utf-8");
$redis= new Redis();
$redis->connect("127.0.0.1","6379");
$pdo= new PDO("mysql:host=127.0.0.1;dbname=test","root","root");
$tel=$_POST{'tel'};
$code=$_POST['code'];
$name=$_POST['name'];
$pwd=$_POST['pwd'];
$time=date("Y-m-d H:i:s");
$rediscode=$redis->get("code".$tel);
if($rediscode){
    if($rediscode=$code){
        $sql="insert into duanxin VALUES ('','$name','$pwd','$tel','$time')";
        $res=$pdo->exec($sql);
        if($res){
            $data=array("code"=>0,"msg"=>"注册成功！");
        }else{
            $data=array("code"=>2,"msg"=>"注册失败！");
        }
    }else{
        $data=array("code"=>1,"msg"=>"验证码有误！");
    }
}else{
    $data=array('code'=>3,"msg"=>"验证码过期");
}
echo json_encode($data);

